<template>
	<view>
		<view class="header">
			<image src="../../../../static/icons/arrl.png" mode=""@tap="back"></image>
			<text>乐居</text>
		</view>
		<view class="serial">
			<view>
				<text>订单编号:</text>
				<text>{{list[0].orderSn}}</text>
			</view>
			<view>
				<text>订单金额:</text>
				<text>{{result}}元</text>
			</view>
		</view>
		<view class="paym">选择支付方式</view>
		 <radio-group @change="radioChange" class="payType">
			<view class="item">
				<view>
					 <image src="../../../../static/icons/alipay.png" mode=""></image>
					 <view>支付宝支付</view>
				 </view>
				<view>
				     <radio value="1" color="#354e44" checked="true" />
				</view>
			</view>
			<view class="item">
				<view>
					 <image src="../../../../static/icons/wxpay.png" mode=""></image>
					 <view>微信支付</view>
				 </view>
				<view>
				     <radio value="2" color="#354e44" />
				</view>
			</view>
        </radio-group>
		<view class="nowPay" @tap="nowMoney">立即支付</view>
		<view class="deal">
			<text>点击立即支付，即代表您同意</text>
			<text>《条款协议》</text>
		</view>
	</view>
</template>

<script>
	import { getPreOrderById,addConfirmOrder,payConfirm } from "../../../../api/home/order.js"
	export default {
		data() {
			return {
				list:[{orderSn:""}],
				radioId:1,
				orderId:""
			};
		},
		methods:{
			back() {
				var len = getCurrentPages().length
				if (len > 1) {
					uni.navigateBack({
						delta:1
					})
				} else {
					uni.switchTab({
						url:"/pages/home/home"
					})
				}
			},
			radioChange(e) {
				console.log(e)
				this.radioId = Number(e.detail.value)
			},
			nowMoney(){
				payConfirm({
					orderId:this.orderId,
					payType:this.radioId
				}).then(res=>{
					console.log(res)
					uni.navigateTo({
						url:`/pages/home/buy/paySuccess/paySuccess?prcie=${this.result}`
					})
				})
			}
		},
		computed:{
			result() {
				var total = this.list.reduce((res,cur)=>{
					return res + cur.productPrice * cur.productQuantity
				},0)
				return total
			}
		},
		onLoad(options) {
			this.orderId = options.id
			getPreOrderById(options.id).then(res=>{
				this.list = res.data.orderItems
				console.log(this.list)
			})
		}
	}
</script>

<style lang="scss" scoped>
.header {
	position: relative;
	display: flex;
	align-items: center;
	justify-content: center;
	background-color: #354e44;
	height: 60rpx;
	padding: 14rpx 6rpx;
	image {
		position: absolute;
		left: 4rpx;
		top: 50%;
		transform: translateY(-50%);
		width: 40rpx;
		height: 40rpx;
	}
	text {
		font-size: 32rpx;
		color: #FFFFFF;
		font-weight: bolder;
	}
}
.serial {
	padding-bottom: 40rpx;
	view {
		width: 94%;
		line-height: 90rpx;
		margin: 0 auto;
		font-size: 32rpx;
		>text {
			&:first-child {
				color: #7d7d7d;
				margin-right: 10rpx;
			}
			&:last-child {
				color: #000;
			}
		}
	}
}
.paym {
	width: 94%;
	font-size: 34rpx;
	color: #000;
	margin: 0 auto;
}
.payType {
	width: 94%;
	margin: 0 auto;
	padding-bottom: 40rpx;
	.item {
		display: flex;
		justify-content: space-between;
		align-items: center;
		height: 120rpx;
		>view {
			&:nth-child(1) {
				display: flex;
				align-items: center;
				image {
					width: 80rpx;
					height: 80rpx;
					margin-right: 20rpx;
				}
			}
		}
	}
}
.nowPay {
	width: 70%;
	height: 80rpx;
	border-radius: 80rpx;
	background-color: #354e44;
	margin: 20rpx auto 0;
	color: #FFFFFF;
	text-align: center;
	line-height: 80rpx;
}
.deal {
	display: flex;
	justify-content: center;
	font-size: 24rpx;
	color: #999999;
	margin-top: 10rpx;
	>text {
		&:last-child {
			color: #5a9ef7;
		}
	}
}
</style>
